
/**
 * 基础工具
 **/
var baseutil = {
    getParams: function(){
        var query = location.search.substring(1);
        var result = new Array();
        if (query) {
            var arQuery = query.split("&");
            for (var i = 0; i < arQuery.length; i++) {
                var pos = arQuery[i].indexOf("=");
                var qName = arQuery[i].substring(0, pos);
                //qName = qName.toLowerCase();
                var qValue = arQuery[i].substring(pos + 1);
                result[qName] = qValue;
            }
        }
        return result;
    },
    getParamsX: function(){
        var location_url = top.location;
        location_url = location_url.toString();
        var idxq = location_url.indexOf("#");
        var result = new Array();
        if (idxq >= 0) {
            var params = location_url.substring(idxq + 1);
            var arQuery = params.split("&");
            for (var i = 0; i < arQuery.length; i++) {
                var pos = arQuery[i].indexOf("=");
                var qName = arQuery[i].substring(0, pos);
                var qValue = arQuery[i].substring(pos + 1);
                result[qName] = qValue;
            }
        }
        return result;
    },
    isEmpty: function(s){
        if (s == null || s == "") {
            return true;
        }
        return false;
    },
    isNull: function(s){
        if (typeof(s)==undefined || s == null || s == undefined || s == "" || s == "undefined" || s == "null") {
            return true;
        }
        return false;
    },
	converNullToValue : function(param, value){
		return this.isNull(param) ? value : param;
	},
	containsSpecialWord :function(str){
		var pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~！@#￥……&*（）——|{}【】‘；：”“'。，、？\"]"); 
		return pattern.test(str);
	},
	parseDate : function(str){
		try{
			var stime = str.replace(/-/g,':').replace(' ',':');
			stime = stime.split(':');
			var smonth = parseInt(stime[1]);
			return new Date(stime[0],smonth,stime[2],stime[3],stime[4],0);
		}catch(e){
			alert("日期转换发生异常:" + e);
			return null;
		}
	},
	setCookie : function(c_name,value,expiredays){
		var exdate=new Date();
		exdate.setDate(exdate.getDate()+expiredays);
		document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? ";path=/" : ";expires="+exdate.toGMTString()+";path=/");
	},
	getCookie : function(cname){
		var name = cname + "=";
		var ca = document.cookie.split(';');
		for(var i=0; i<ca.length; i++) {
			var c = ca[i].trim();
			if (c.indexOf(name)==0) return c.substring(name.length,c.length);
		}
		return "";
	},
	formatFloatNumer : function(n){
		try{
			var nn = new Number(n);
			return nn.toFixed(2);
		}catch(e){
			return -1;
		}
	}
    
};

function tm_bindPasswordLevelChecker(id){
	$('#'+id).keyup(function() { 
		var strongRegex = new RegExp("^(?=.{8,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\\W).*$", "g"); 
		var mediumRegex = new RegExp("^(?=.{7,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$", "g"); 
		var enoughRegex = new RegExp("(?=.{6,}).*", "g"); 
	
		if (false == enoughRegex.test($(this).val())) { 
			$('#tm_level').removeClass('pw-weak'); 
			$('#tm_level').removeClass('pw-medium'); 
			$('#tm_level').removeClass('pw-strong'); 
			$('#tm_level').addClass(' pw-defule'); 
			 //密码小于六位的时候，密码强度图片都为灰色 
		} 
		else if (strongRegex.test($(this).val())) { 
			$('#tm_level').removeClass('pw-weak'); 
			$('#tm_level').removeClass('pw-medium'); 
			$('#tm_level').removeClass('pw-strong'); 
			$('#tm_level').addClass(' pw-strong'); 
			 //密码为八位及以上并且字母数字特殊字符三项都包括,强度最强 
		} 
		else if (mediumRegex.test($(this).val())) { 
			$('#tm_level').removeClass('pw-weak'); 
			$('#tm_level').removeClass('pw-medium'); 
			$('#tm_level').removeClass('pw-strong'); 
			$('#tm_level').addClass(' pw-medium'); 
			 //密码为七位及以上并且字母、数字、特殊字符三项中有两项，强度是中等 
		} 
		else { 
			$('#tm_level').removeClass('pw-weak'); 
			$('#tm_level').removeClass('pw-medium'); 
			$('#tm_level').removeClass('pw-strong'); 
			$('#tm_level').addClass('pw-weak'); 
			 //如果密码为6为及以下，就算字母、数字、特殊字符三项都包括，强度也是弱的 
		} 
		//return true; 
	}); 
}


function tm_fn_page_to(evt, url, pageid){
	var e = evt || window.event || arguments.callee.caller.arguments[0];
	if(e && e.keyCode==13){
		if(!/^[0-9]*$/.test(pageid)){ 
			pageid = 1;
		}
		var epagesize = $("#tm_pager_pagesize").val();
		window.location.href = url + "epage=" + pageid + "&epagesize="+epagesize; 
		return false;
	}
}


function tm_fn_pagesize(url, pagesize){
	window.location.href = url + "epage=1&epagesize=" + pagesize; 
}

function showTipOfFlashPlug(){
	layer.tips('<b>无法上传？</b><br/>请检查浏览器是否安装（或启用）了Flash插件，<a href="http://www.tomexam.com/help.jsp?code=flashupload" target="_blank" class="tma-help-lnk">点击了解更多</a>。', "#btn_photo", {tips: [1, '#368ee0'], time:8000});
}

function doCheckBrowserSupport(){
	try{
		var tomjson = {"name":"tomexam","version":"professional"};
		var jsonStr = JSON.stringify(tomjson);
		window.localStorage.setItem("softinfo", jsonStr);
		var lsdata = window.localStorage.getItem("softinfo");
		var lsjson = JSON.parse(lsdata);
		lsjson["auth"] = "all";
		return true;
	}catch(e){
		return false;
	}
}

function doPreviewPicture(vurl){
	window.top.layer.open({
	  type: 1,
	  title: false,
	  skin: 'layui-layer-rim',
	  area:['auto','auto'],
	  shadeClose: true,
	  content: '<img src="'+vurl+'" width="388" />'
	});
}

function getParentElementById(id){
	if(window.top.frames["tmMain"]){
		return $(window.top.frames["tmMain"].document).find(id);
	}else{
		return $(id, window.parent.document);
	}
}


/**
 * <td class="tm-datatip" data-dcreator="" data-dcreationtime="" data-dmodifier="" data-dlastmodtime="">
 */
function doBindDataTip(){
	var v_tip_con_exisit = $(".tmv_data_tip").length>0;
	if(!v_tip_con_exisit){
		$("body").append("<div class='tmv_data_tip'></div>");
	}

	$(".tm-datatip").mousemove(function(){
		var vctop = $(this).offset().top;
		var vcleft = $(this).offset().left + 150;
		$(".tmv_data_tip").css({"top" : vctop + "px", "left" : vcleft + "px"}).show();
		var vchtml = "<p>创建人："+$(this).data("dcreator")+"</p><p>创建时间："+$(this).data("dcreationtime")+"</p><p>修改人："+$(this).data("dmodifier")+"</p><p>修改时间："+$(this).data("dlastmodtime")+"</p>";
		$(".tmv_data_tip").html(vchtml);
	});
	$(".tm-datatip").mouseout(function(){
		$(".tmv_data_tip").hide();
	});

}


